import sys
import matplotlib.pyplot as plt
import get_metric
plt.rcParams['font.sans-serif'] = ['Times New Roman']
plt.rcParams.update({"font.size":20})


if __name__ == "__main__":
    file_name = sys.argv[1]
    time_list, delay_list = get_metric.get_delay_list(file_name)

    time_list = [t - time_list[0] for t in time_list]
    
    loss_time_list = get_metric.get_loss_list(file_name)
    loss_time_list = [t - loss_time_list[0] for t in loss_time_list]


    filename_a = sys.argv[2]
    filename_b = sys.argv[3]


    loss_time_list_a = get_metric.get_loss_list(filename_a)
    loss_time_list_a = [t - loss_time_list_a[0] for t in loss_time_list_a]
    loss_time_list_b = get_metric.get_loss_list(filename_b)
    loss_time_list_b = [t - loss_time_list_b[0] for t in loss_time_list_b]

    wireless_loss_time_list = []
    for t in loss_time_list_a:
        if t not in loss_time_list_b:
            wireless_loss_time_list.append(t)

    bottlenack_loss_time_list = []
    for t in loss_time_list:
        if t not in wireless_loss_time_list:
            bottlenack_loss_time_list.append(t)

    plt.figure(figsize=(6, 3))
    plt.plot(time_list, delay_list)


    for loss_time in bottlenack_loss_time_list:
        if loss_time <= time_list[-1]:
            plt.axvline(loss_time, color = 'g')


    for loss_time in wireless_loss_time_list:
        if loss_time <= time_list[-1]:
            plt.axvline(loss_time, color = 'r', linestyle ="--")

    
    plt.xlabel('Time (s)')
    plt.ylabel('Delay (s)')
    plt.grid()
    plt.tight_layout()
    file_name = __file__.split('/')[-1].split('.')[0]
    plt.savefig(f"{file_name}.png", bbox_inches='tight')
    # plt.show()
